﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Web.Configuration;
using System.Web.SessionState;
using System.Collections;
using System.Data;
using System.Configuration;
using System.Web.Security;
using System.Text.RegularExpressions;
using System.IO;
using System.Text;
using System.Data.Common;
using System.Data.SqlClient;

public class manage
{
    SqlConnection MyConnection = null;
    public void Open()
    {
        if (MyConnection == null)
        {
            MyConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
        }
        MyConnection.Open();
    }

    public void Close()
    {
        if (MyConnection != null)
        {
            MyConnection.Close();
        }
    }

    public manage()
    {
    }


    public DataTable selectdictionary(int kind)
    {
        Open();
        DataTable dt = new DataTable();
        try
        {
            SqlCommand MyCommand = new SqlCommand("select * from dictionary where di_state=1 and di_type=@kind", MyConnection);
            MyCommand.Parameters.Add("@kind", SqlDbType.Int).Value = kind;
            SqlDataAdapter sda = new SqlDataAdapter(MyCommand);
            sda.Fill(dt);
        }
        catch (Exception e)
        {
            Close();
        }
        Close();
        return dt;
    }

    public DataTable selectdictionary_sex(int kind)
    {
        Open();
        DataTable dt = new DataTable();
        try
        {
            SqlCommand MyCommand = new SqlCommand("select * from dictionary where di_state=1 and di_code<>9 and di_type=@kind", MyConnection);
            MyCommand.Parameters.Add("@kind", SqlDbType.Int).Value = kind;
            SqlDataAdapter sda = new SqlDataAdapter(MyCommand);
            sda.Fill(dt);
        }
        catch (Exception e)
        {
            Close();
        }
        Close();
        return dt;
    }

    public DataTable selectjobtype()
    {
        Open();
        DataTable dt = new DataTable();
        try
        {
            SqlCommand MyCommand = new SqlCommand("select * from jobtype where jt_state=1 ", MyConnection);
            // MyCommand.Parameters.Add("@kind", SqlDbType.Int).Value = kind;
            SqlDataAdapter sda = new SqlDataAdapter(MyCommand);
            sda.Fill(dt);
        }
        catch (Exception e)
        {
            Close();
        }
        Close();
        return dt;
    }

    public string deletecompany(string id)
    {
        string str = string.Empty;
        Open();
        try
        {
            SqlCommand MyCommand = new SqlCommand();
            MyCommand.Connection = MyConnection;
            SqlTransaction MyTrans = MyConnection.BeginTransaction("Tran");
            MyCommand.Transaction = MyTrans;
            string[] ids = id.Split(',');
            if (ids.Length > 1)
            {
                for (int i = 0; i < ids.Length - 1; i++)
                {
                    MyCommand.Parameters.Clear();
                    MyCommand.CommandText = "delete from companyuser where cu_no=@cuno";
                    MyCommand.Parameters.Add("@cuno", SqlDbType.Int).Value = ids[i];
                    MyCommand.ExecuteNonQuery();
                }
            }
            else
            {
                MyCommand.CommandText = "delete from companyuser where cu_no=@cuno";
                MyCommand.Parameters.Add("@cuno", SqlDbType.Int).Value = ids[0];
                MyCommand.ExecuteNonQuery();
            }
            MyTrans.Commit();
            str = "删除成功";
        }
        catch (Exception e)
        {
            Close();
            str = "已有相关数据，不能删除";
        }
        Close();
        return str;
    }

    public string showhidecompany(string id, int state)
    {
        string str = string.Empty;
        Open();
        try
        {
            SqlCommand MyCommand = new SqlCommand();
            MyCommand.Connection = MyConnection;
            SqlTransaction MyTrans = MyConnection.BeginTransaction("Tran");
            MyCommand.Transaction = MyTrans;
            string[] ids = id.Split(',');
            for (int i = 0; i < ids.Length - 1; i++)
            {
                MyCommand.Parameters.Clear();
                MyCommand.CommandText = "update companyuser set cu_hide=@state where cu_no=@cuno";
                MyCommand.Parameters.Add("@state", SqlDbType.Int).Value = state;
                MyCommand.Parameters.Add("@cuno", SqlDbType.Int).Value = ids[i];
                MyCommand.ExecuteNonQuery();
            }
            MyTrans.Commit();
            str = "操作成功";
        }
        catch (Exception e)
        {
            str = "操作失败";
            Close();
        }
        Close();
        return str;
    }

    public Hashtable selectsimpleCompany(int id)
    {
        Open();
        DataTable dt = new DataTable();
        try
        {
            SqlCommand MyCommand = MyConnection.CreateCommand();
            MyCommand.Connection = MyConnection;
            MyCommand.CommandText = "select * from companyuser where cu_no =@cuno";
            MyCommand.Parameters.Add("@cuno", SqlDbType.Int).Value = id;
            SqlDataAdapter sda = new SqlDataAdapter(MyCommand);

            sda.Fill(dt);
        }
        catch (Exception e)
        {
            Close();
        }
        Close();
        ArrayList al = DataTable2ArrayList(dt);
        return al.Count > 0 ? (Hashtable)al[0] : null;
    }

    private static ArrayList DataTable2ArrayList(DataTable data)
    {
        ArrayList array = new ArrayList();
        for (int i = 0; i < data.Rows.Count; i++)
        {
            DataRow row = data.Rows[i];

            Hashtable record = new Hashtable();
            for (int j = 0; j < data.Columns.Count; j++)
            {
                object cellValue = row[j];
                if (cellValue.GetType() == typeof(DBNull))
                {
                    cellValue = null;
                }
                record[data.Columns[j].ColumnName] = cellValue;
            }
            array.Add(record);
        }
        return array;
    }



    public string SaveCompany(Hashtable user)
    {
        string res = string.Empty;
        Open();
        // SqlTransaction MyTrans;
        //  MyTrans = MyConnection.BeginTransaction("Tran");
        try
        {
            string str = "";
            SqlCommand cmd = MyConnection.CreateCommand();
            cmd.Connection = MyConnection;
            //cmd.Transaction = MyTrans;

            string id = (user["cu_no"] == null || user["cu_no"].ToString() == "" || user["cu_no"].ToString() == "0") ? "0" : user["cu_no"].ToString();
            if (id == "0")
            {
                cmd.CommandText = "insert into companyuser (cu_user,cu_password,cu_name,cu_trade,cu_property,cu_license,cu_area,cu_contact,cu_tel,cu_fax,cu_email,cu_url,cu_state,cu_apptime,cu_kind,cu_introduce," +
                    "cu_effecttime,cu_address) values (@cu_user,@cu_password,@cu_name,@cu_trade,@cu_property,@cu_license,@cu_area,@cu_contact,@cu_tel,@cu_fax,@cu_email,@cu_url,@cu_state,@cu_apptime,@cu_kind,@cu_introduce," +
                    "@cu_effecttime,@cu_address);SELECT @@IDENTITY AS 'MaxID'";

                cmd.Parameters.Add("@cu_user", SqlDbType.NVarChar).Value = user["cu_user"];
                cmd.Parameters.Add("@cu_state", SqlDbType.Int).Value = 1;
                cmd.Parameters.Add("@cu_apptime", SqlDbType.DateTime).Value = DateTime.Now;
                cmd.Parameters.Add("@cu_effecttime", SqlDbType.Int).Value = user["cu_effecttime"];
                cmd.Parameters.Add("@cu_kind", SqlDbType.Int).Value = user["cu_kind"];
            }
            else
            {
                cmd.CommandText = "update companyuser set cu_password=@cu_password,cu_name=@cu_name,cu_trade=@cu_trade,cu_property=@cu_property,cu_license=@cu_license,cu_area=@cu_area,cu_contact=@cu_contact,cu_tel=@cu_tel,cu_fax=@cu_fax,cu_email=@cu_email,cu_url=@cu_url,cu_introduce=@cu_introduce," +
                    "cu_address=@cu_address where cu_no=@cu_no";
                cmd.Parameters.Add("@cu_no", SqlDbType.Int).Value = user["cu_no"].ToString();
            }

            cmd.Parameters.Add("@cu_password", SqlDbType.NVarChar).Value = user["cu_password"].ToString();
            cmd.Parameters.Add("@cu_name", SqlDbType.NVarChar).Value = user["cu_name"].ToString();
            cmd.Parameters.Add("@cu_trade", SqlDbType.NVarChar).Value = user["cu_trade"].ToString();
            cmd.Parameters.Add("@cu_property", SqlDbType.NVarChar).Value = user["cu_property"].ToString();
            cmd.Parameters.Add("@cu_license", SqlDbType.NVarChar).Value = user["cu_license"].ToString();
            cmd.Parameters.Add("@cu_area", SqlDbType.NVarChar).Value = user["cu_area"].ToString();
            //cmd.Parameters.Add("@cu_postcode", SqlDbType.NVarChar).Value = user["cu_postcode"].ToString();
            cmd.Parameters.Add("@cu_contact", SqlDbType.NVarChar).Value = user["cu_contact"].ToString();
            cmd.Parameters.Add("@cu_tel", SqlDbType.NVarChar).Value = user["cu_tel"].ToString();
            cmd.Parameters.Add("@cu_fax", SqlDbType.NVarChar).Value = user["cu_fax"].ToString();
            cmd.Parameters.Add("@cu_email", SqlDbType.NVarChar).Value = user["cu_email"].ToString();
            cmd.Parameters.Add("@cu_url", SqlDbType.NVarChar).Value = user["cu_url"].ToString();
            cmd.Parameters.Add("@cu_introduce", SqlDbType.NVarChar).Value = user["cu_introduce"].ToString();
            cmd.Parameters.Add("@cu_address", SqlDbType.NVarChar).Value = user["cu_address"].ToString();
            cmd.ExecuteNonQuery();


            //  MyTrans.Commit();
            res = "保存成功";

        }
        catch (Exception e)
        {
            // MyTrans.Rollback("Tran");
            res = "保存失败";
        }
        Close();
        return res;
    }


    public string deleteRecruit(string id)
    {
        string str = string.Empty;
        Open();
        try
        {
            SqlCommand MyCommand = new SqlCommand();
            MyCommand.Connection = MyConnection;
            SqlTransaction MyTrans = MyConnection.BeginTransaction("Tran");
            MyCommand.Transaction = MyTrans;
            string[] ids = id.Split(',');
            if (ids.Length > 1)
            {
                for (int i = 0; i < ids.Length - 1; i++)
                {
                    MyCommand.Parameters.Clear();
                    MyCommand.CommandText = "delete from recruit where re_no=@re_no";
                    MyCommand.Parameters.Add("@re_no", SqlDbType.Int).Value = ids[i];
                    MyCommand.ExecuteNonQuery();
                }
            }
            else
            {
                MyCommand.CommandText = "delete from recruit where re_no=@re_no";
                MyCommand.Parameters.Add("@re_no", SqlDbType.Int).Value = ids[0];
                MyCommand.ExecuteNonQuery();
            }
            MyTrans.Commit();
            str = "删除成功";
        }
        catch (Exception e)
        {
            Close();
            str = "删除失败";
        }
        Close();
        return str;
    }


    public Hashtable selectsimpleRecruit(int id)
    {
        Open();
        DataTable dt = new DataTable();
        try
        {
            SqlCommand MyCommand = MyConnection.CreateCommand();
            MyCommand.Connection = MyConnection;
            MyCommand.CommandText = "select * from recruit where re_no =@reno";
            MyCommand.Parameters.Add("@reno", SqlDbType.Int).Value = id;
            SqlDataAdapter sda = new SqlDataAdapter(MyCommand);

            sda.Fill(dt);
        }
        catch (Exception e)
        {
            Close();
        }
        Close();
        ArrayList al = DataTable2ArrayList(dt);
        return al.Count > 0 ? (Hashtable)al[0] : null;
    }



    public string SaveRecruit(Hashtable user)
    {
        string res = string.Empty;
        Open();
        try
        {
            string str = "";
            SqlCommand cmd = MyConnection.CreateCommand();
            cmd.Connection = MyConnection;

            string id = (user["re_no"] == null || user["re_no"].ToString() == "" || user["re_no"].ToString() == "0") ? "0" : user["re_no"].ToString();
            if (id == "0")
            {
                cmd.CommandText = "insert into recruit (re_isneed,re_needstate,re_cuno,re_name,re_num,re_sex,re_kind,re_edu,re_edu2,re_target,re_jobtype1,re_jobtype2,re_age,re_pay1,re_pay2,re_area,re_effecttime,re_memo" +
                    ",re_inserttime,re_insertip) values (@re_isneed,0,@re_cuno,@re_name,@re_num,@re_sex,@re_kind,@re_edu,@re_edu2,@re_target,@re_jobtype1,@re_jobtype2,@re_age,@re_pay1,@re_pay2,@re_area,@re_effecttime,@re_memo,getDate(),@re_ip);";

                cmd.Parameters.Add("@re_cuno", SqlDbType.NVarChar).Value = user["re_cuno"];
                cmd.Parameters.Add("@re_ip", SqlDbType.NVarChar).Value = user["ip"];
            }
            else
            {
                cmd.CommandText = "update recruit set re_isneed=@re_isneed,re_name=@re_name,re_num=@re_num,re_sex=@re_sex,re_kind=@re_kind,re_edu=@re_edu,re_edu2=@re_edu2,re_target=@re_target,re_jobtype1=@re_jobtype1,re_jobtype2=@re_jobtype2,re_age=@re_age,re_pay1=@re_pay1,re_pay2=@re_pay2," +
                    "re_area=@re_area,re_effecttime=@re_effecttime,re_memo=@re_memo where re_no=@re_no";
                cmd.Parameters.Add("@re_no", SqlDbType.Int).Value = user["re_no"].ToString();
            }

            cmd.Parameters.Add("@re_isneed", SqlDbType.Int).Value = user["re_isneed"].ToString() == "true" ? "1" : "0";
            cmd.Parameters.Add("@re_name", SqlDbType.NVarChar).Value = user["re_name"].ToString();
            cmd.Parameters.Add("@re_num", SqlDbType.Int).Value = user["re_num"].ToString();
            cmd.Parameters.Add("@re_sex", SqlDbType.NVarChar).Value = user["re_sex"].ToString();
            cmd.Parameters.Add("@re_kind", SqlDbType.NVarChar).Value = user["re_kind"].ToString();
            cmd.Parameters.Add("@re_edu", SqlDbType.NVarChar).Value = user["re_edu"].ToString();
            cmd.Parameters.Add("@re_edu2", SqlDbType.NVarChar).Value = user["re_edu2"].ToString() == "true" ? "以上" : "";
            cmd.Parameters.Add("@re_target", SqlDbType.NVarChar).Value = user["re_target"].ToString();
            cmd.Parameters.Add("@re_jobtype1", SqlDbType.NVarChar).Value = user["re_jobtype1"].ToString();
            cmd.Parameters.Add("@re_jobtype2", SqlDbType.NVarChar).Value = user["re_jobtype2"].ToString();
            cmd.Parameters.Add("@re_age", SqlDbType.NVarChar).Value = user["re_age"].ToString();
            cmd.Parameters.Add("@re_pay1", SqlDbType.NVarChar).Value = user["re_pay1"].ToString();
            cmd.Parameters.Add("@re_pay2", SqlDbType.NVarChar).Value = user["re_pay2"].ToString();
            cmd.Parameters.Add("@re_area", SqlDbType.NVarChar).Value = user["re_area"].ToString();
            cmd.Parameters.Add("@re_effecttime", SqlDbType.Int).Value = user["re_effecttime"].ToString();
            cmd.Parameters.Add("@re_memo", SqlDbType.NVarChar).Value = user["re_memo"].ToString();
            cmd.ExecuteNonQuery();
            res = "保存成功";

        }
        catch (Exception e)
        {
            res = "保存失败";
        }
        Close();
        return res;
    }


    public string ShowHideRecruit(string id, int state)
    {
        string str = string.Empty;
        Open();
        try
        {
            SqlCommand MyCommand = new SqlCommand();
            MyCommand.Connection = MyConnection;
            SqlTransaction MyTrans = MyConnection.BeginTransaction("Tran");
            MyCommand.Transaction = MyTrans;
            string[] ids = id.Split(',');
            for (int i = 0; i < ids.Length - 1; i++)
            {
                MyCommand.Parameters.Clear();
                MyCommand.CommandText = "update recruit set re_hide=@state where re_no=@reno";
                MyCommand.Parameters.Add("@state", SqlDbType.Int).Value = state;
                MyCommand.Parameters.Add("@reno", SqlDbType.Int).Value = ids[i];
                MyCommand.ExecuteNonQuery();
            }
            MyTrans.Commit();
            str = "操作成功";
        }
        catch (Exception e)
        {
            str = "操作失败";
            Close();
        }
        Close();
        return str;
    }


    public string RecruitHittoZero(string id)
    {
        string str = string.Empty;
        Open();
        try
        {
            SqlCommand MyCommand = new SqlCommand();
            MyCommand.Connection = MyConnection;
            SqlTransaction MyTrans = MyConnection.BeginTransaction("Tran");
            MyCommand.Transaction = MyTrans;
            string[] ids = id.Split(',');
            for (int i = 0; i < ids.Length - 1; i++)
            {
                MyCommand.Parameters.Clear();
                MyCommand.CommandText = "update recruit set re_hits=0 where re_no=@reno";
                MyCommand.Parameters.Add("@reno", SqlDbType.Int).Value = ids[i];
                MyCommand.ExecuteNonQuery();
            }
            MyTrans.Commit();
            str = "操作成功";
        }
        catch (Exception e)
        {
            str = "操作失败";
            Close();
        }
        Close();
        return str;
    }


    public string RecruitRefresh(string id)
    {
        string str = string.Empty;
        Open();
        try
        {
            SqlCommand MyCommand = new SqlCommand();
            MyCommand.Connection = MyConnection;
            SqlTransaction MyTrans = MyConnection.BeginTransaction("Tran");
            MyCommand.Transaction = MyTrans;
            string[] ids = id.Split(',');
            for (int i = 0; i < ids.Length - 1; i++)
            {
                MyCommand.Parameters.Clear();
                MyCommand.CommandText = "update recruit set re_inserttime=getDate() where re_no=@reno";
                MyCommand.Parameters.Add("@reno", SqlDbType.Int).Value = ids[i];
                MyCommand.ExecuteNonQuery();
            }
            MyTrans.Commit();
            str = "操作成功";
        }
        catch (Exception e)
        {
            str = "操作失败";
            Close();
        }
        Close();
        return str;
    }


    public string updateexamine(Hashtable user)
    {
        string res = "";
        Open();
        try
        {
            SqlCommand MyCommand = new SqlCommand();
            MyCommand.Connection = MyConnection;
            SqlTransaction MyTrans = MyConnection.BeginTransaction("Tran");
            MyCommand.Transaction = MyTrans;

            MyCommand.Parameters.Clear();
            MyCommand.CommandText = "update companyuser set cu_apptime=getDate(),cu_effecttime=@time,cu_kind=@kind where cu_no=@cuno";
            MyCommand.Parameters.Add("@time", SqlDbType.Int).Value = user["cu_effecttime"];
            MyCommand.Parameters.Add("@kind", SqlDbType.NVarChar).Value = user["cu_kind"];
            MyCommand.Parameters.Add("@cuno", SqlDbType.Int).Value = user["cu_no"];
            MyCommand.ExecuteNonQuery();

            if (user["cu_ismoney"].ToString() == "true")
            {
                MyCommand.Parameters.Clear();
                MyCommand.CommandText = "insert into compayment(cm_cuno,cm_money,cm_inserttime,cm_insertuser,cm_memo,cm_inserip) values(@cuno,@money,getDate(),@user,@memo,@ip)";
                MyCommand.Parameters.Add("@cuno", SqlDbType.Int).Value = user["cu_no"];
                MyCommand.Parameters.Add("@money", SqlDbType.NVarChar).Value = user["cm_money"];
                MyCommand.Parameters.Add("@user", SqlDbType.NVarChar).Value = user["userid"];
                MyCommand.Parameters.Add("@memo", SqlDbType.NVarChar).Value = user["cm_memo"];
                MyCommand.Parameters.Add("@ip", SqlDbType.NVarChar).Value = user["ip"];
                MyCommand.ExecuteNonQuery();
            }

            MyTrans.Commit();
            res = "操作成功";
        }
        catch (Exception e)
        {
            res = "操作失败";
            Close();
        }
        Close();
        return res;
    }


    public string updatemoney(Hashtable user)
    {
        string res = "";
        Open();
        try
        {
            SqlCommand MyCommand = new SqlCommand();
            MyCommand.Connection = MyConnection;
            MyCommand.Parameters.Clear();
            MyCommand.CommandText = "insert into compayment(cm_cuno,cm_money,cm_inserttime,cm_insertuser,cm_memo,cm_inserip) values(@cuno,@money,getDate(),@user,@memo,@ip)";
            MyCommand.Parameters.Add("@cuno", SqlDbType.Int).Value = user["cu_no"];
            MyCommand.Parameters.Add("@money", SqlDbType.NVarChar).Value = user["cm_money"];
            MyCommand.Parameters.Add("@user", SqlDbType.NVarChar).Value = user["userid"];
            MyCommand.Parameters.Add("@memo", SqlDbType.NVarChar).Value = user["cm_memo"];
            MyCommand.Parameters.Add("@ip", SqlDbType.NVarChar).Value = user["ip"];
            MyCommand.ExecuteNonQuery();

            res = "操作成功";
        }
        catch (Exception e)
        {
            res = "操作失败";
            Close();
        }
        Close();
        return res;
    }

    public string getCompanyname(string cuno)
    {
        string res = "";
        Open();
        try
        {
            SqlCommand MyCommand = new SqlCommand("select cu_name from companyuser where cu_no=@cuno", MyConnection);
            MyCommand.Parameters.Add("@cuno", SqlDbType.Int).Value = cuno;
            res = MyCommand.ExecuteScalar().ToString();
        }
        catch (Exception e)
        {

        }
        Close();
        return res;
    }

    public string examinepass(string state, string cunostr)
    {
        string res = "";
        Open();
        try
        {
            SqlCommand MyCommand = new SqlCommand();
            MyCommand.Connection = MyConnection;
            SqlTransaction MyTrans = MyConnection.BeginTransaction("Tran");
            MyCommand.Transaction = MyTrans;
            string[] ids = cunostr.Split(',');
            for (int i = 0; i < ids.Length - 1; i++)
            {
                MyCommand.Parameters.Clear();
                MyCommand.CommandText = "update companyuser set cu_logostate=@state where cu_no=@cuno";
                MyCommand.Parameters.Add("@cuno", SqlDbType.Int).Value = ids[i];
                MyCommand.Parameters.Add("@state", SqlDbType.Int).Value = state;
                MyCommand.ExecuteNonQuery();
            }
            MyTrans.Commit();
            res = "操作成功";
        }
        catch (Exception e)
        {
            res = "操作失败";
            Close();
        }
        Close();
        return res;
    }


    public string deletepic(string cunostr)
    {
        string res = "";
        Open();
        try
        {
            SqlCommand MyCommand = new SqlCommand();
            MyCommand.Connection = MyConnection;
            SqlTransaction MyTrans = MyConnection.BeginTransaction("Tran");
            MyCommand.Transaction = MyTrans;
            string[] ids = cunostr.Split(',');
            for (int i = 0; i < ids.Length - 1; i++)
            {
                MyCommand.Parameters.Clear();
                MyCommand.CommandText = "update companyuser set cu_logostate=9 where cu_no=@cuno";
                MyCommand.Parameters.Add("@cuno", SqlDbType.Int).Value = ids[i];
                MyCommand.ExecuteNonQuery();
            }
            MyTrans.Commit();
            res = "操作成功";
        }
        catch (Exception e)
        {
            res = "操作失败";
            Close();
        }
        Close();
        return res;
    }


    public string deletemessage(string id)
    {
        string res = "";
        Open();
        try
        {
            SqlCommand MyCommand = new SqlCommand();
            MyCommand.Connection = MyConnection;
            MyCommand.CommandText = "delete from  consult where cs_no=@csno";
            MyCommand.Parameters.Add("@csno", SqlDbType.Int).Value = id;
            MyCommand.ExecuteNonQuery();

            res = "操作成功";
        }
        catch (Exception e)
        {
            res = "操作失败";
            Close();
        }

        Close();
        return res;
    }

    public Hashtable selectsimpleconsult(int id)
    {
        Open();
        DataTable dt = new DataTable();
        try
        {
            SqlCommand MyCommand = MyConnection.CreateCommand();
            MyCommand.Connection = MyConnection;
            MyCommand.CommandText = "select * from consult where cs_no =@csno";
            MyCommand.Parameters.Add("@csno", SqlDbType.Int).Value = id;
            SqlDataAdapter sda = new SqlDataAdapter(MyCommand);

            sda.Fill(dt);
        }
        catch (Exception e)
        {
            Close();
        }
        Close();
        ArrayList al = DataTable2ArrayList(dt);
        return al.Count > 0 ? (Hashtable)al[0] : null;
    }


    public string updateconsult(Hashtable user)
    {
        string res = "";
        Open();
        try
        {
            SqlCommand MyCommand = new SqlCommand();
            MyCommand.Connection = MyConnection;

            MyCommand.Parameters.Clear();
            MyCommand.CommandText = "update consult set cs_hftime=getDate(),cs_hfcontent=@content where cs_no=@csno";
            MyCommand.Parameters.Add("@content", SqlDbType.NVarChar).Value = user["cs_hfcontent"];
            MyCommand.Parameters.Add("@csno", SqlDbType.Int).Value = user["cs_no"];
            MyCommand.ExecuteNonQuery();
            res = "操作成功";
        }
        catch (Exception e)
        {
            res = "操作失败";
            Close();
        }
        Close();
        return res;
    }


    public string deleteStudent(string id)
    {
        string str = string.Empty;
        Open();
        try
        {
            SqlCommand MyCommand = new SqlCommand();
            MyCommand.Connection = MyConnection;
            SqlTransaction MyTrans = MyConnection.BeginTransaction("Tran");
            MyCommand.Transaction = MyTrans;
            string[] ids = id.Split(',');
            if (ids.Length > 1)
            {
                for (int i = 0; i < ids.Length - 1; i++)
                {
                    MyCommand.Parameters.Clear();
                    MyCommand.CommandText = "delete from student where st_no=@st_no";
                    MyCommand.Parameters.Add("@st_no", SqlDbType.Int).Value = ids[i];
                    MyCommand.ExecuteNonQuery();
                }
            }
            else
            {
                MyCommand.CommandText = "delete from student where st_no=@st_no";
                MyCommand.Parameters.Add("@st_no", SqlDbType.Int).Value = ids[0];
                MyCommand.ExecuteNonQuery();
            }
            MyTrans.Commit();
            str = "删除成功";
        }
        catch (Exception e)
        {
            Close();
            str = "删除失败";
        }
        Close();
        return str;
    }


    public string changeStudentstate(string id, string state, string ip)
    {
        string str = string.Empty;
        Open();
        try
        {
            SqlCommand MyCommand = new SqlCommand();
            MyCommand.Connection = MyConnection;
            SqlTransaction MyTrans = MyConnection.BeginTransaction("Tran");
            MyCommand.Transaction = MyTrans;
            string[] ids = id.Split(',');

            for (int i = 0; i < ids.Length - 1; i++)
            {
                MyCommand.Parameters.Clear();
                MyCommand.CommandText = "update student set st_state=@state,st_modifytime=getDate(),st_modifyip=@ip where st_no=@st_no";
                MyCommand.Parameters.Add("@st_no", SqlDbType.Int).Value = ids[i];
                MyCommand.Parameters.Add("@state", SqlDbType.Int).Value = state;
                MyCommand.Parameters.Add("@ip", SqlDbType.NVarChar).Value = ip;
                MyCommand.ExecuteNonQuery();
            }
            MyTrans.Commit();
            str = "操作成功";
        }
        catch (Exception e)
        {
            Close();
            str = "操作失败";
        }
        Close();
        return str;
    }

    public Hashtable selectsimplestudent(string id)
    {
        Open();
        DataTable dt = new DataTable();
        try
        {
            SqlCommand MyCommand = MyConnection.CreateCommand();
            MyCommand.Connection = MyConnection;
            MyCommand.CommandText = "select * from student where st_no =@stno";
            MyCommand.Parameters.Add("@stno", SqlDbType.Int).Value = id;
            SqlDataAdapter sda = new SqlDataAdapter(MyCommand);

            sda.Fill(dt);
        }
        catch (Exception e)
        {
            Close();
        }
        Close();
        ArrayList al = DataTable2ArrayList(dt);
        return al.Count > 0 ? (Hashtable)al[0] : null;
    }

    public string updatestudent(Hashtable user)
    {
        string str = string.Empty;
        Open();
        try
        {
            SqlCommand MyCommand = new SqlCommand();
            MyCommand.Connection = MyConnection;
            string id = (user["st_no"] == null || user["st_no"].ToString() == "" || user["st_no"].ToString() == "0") ? "0" : user["st_no"].ToString();
            if (id == "0")
            {
                MyCommand.CommandText = "insert into student(st_name,st_sex,st_nation,st_card,st_school,st_finishtime,st_education,st_profession,st_address,st_email,st_postcode,st_mobile,st_tel,st_hard,st_will1,st_will2,st_need,st_goto,st_inserttime,st_insertip,st_state)" +
                    " values(@st_name,@st_sex,@st_nation,@st_card,@st_school,@st_finishtime,@st_education,@st_profession,@st_address,@st_email,@st_postcode,@st_mobile,@st_tel,@st_hard,@st_will1,@st_will2,@st_need,@st_goto,getDate(),@st_insertip,0)";
                MyCommand.Parameters.Add("@st_insertip", SqlDbType.NVarChar).Value = user["st_insertip"];
            }
            else
            {
                MyCommand.CommandText = "update student set st_name=@st_name,st_sex=@st_sex,st_nation=@st_nation,st_card=@st_card,st_school=@st_school,st_finishtime=@st_finishtime,st_education=@st_education,st_profession=@st_profession," +
                    "st_address=@st_address,st_email=@st_email,st_postcode=@st_postcode,st_mobile=@st_mobile,st_tel=@st_tel,st_hard=@st_hard,st_will1=@st_will1,st_will2=@st_will2,st_need=@st_need,st_goto=@st_goto where st_no=@st_no";
                MyCommand.Parameters.Add("@st_no", SqlDbType.Int).Value = id;
            }
            MyCommand.Parameters.Add("@st_name", SqlDbType.NVarChar).Value = user["st_name"];
            MyCommand.Parameters.Add("@st_sex", SqlDbType.Int).Value = user["st_sex"];
            MyCommand.Parameters.Add("@st_nation", SqlDbType.NVarChar).Value = user["st_nation"];
            MyCommand.Parameters.Add("@st_card", SqlDbType.NVarChar).Value = user["st_card"];
            MyCommand.Parameters.Add("@st_school", SqlDbType.NVarChar).Value = user["st_school"];
            MyCommand.Parameters.Add("@st_finishtime", SqlDbType.NVarChar).Value = user["st_finishtime"];
            MyCommand.Parameters.Add("@st_education", SqlDbType.Int).Value = user["st_education"];
            MyCommand.Parameters.Add("@st_profession", SqlDbType.NVarChar).Value = user["st_profession"];
            MyCommand.Parameters.Add("@st_address", SqlDbType.NVarChar).Value = user["st_address"];
            MyCommand.Parameters.Add("@st_email", SqlDbType.NVarChar).Value = user["st_email"];
            MyCommand.Parameters.Add("@st_postcode", SqlDbType.NVarChar).Value = user["st_postcode"];
            MyCommand.Parameters.Add("@st_mobile", SqlDbType.NVarChar).Value = user["st_mobile"];
            MyCommand.Parameters.Add("@st_tel", SqlDbType.NVarChar).Value = user["st_tel"];
            MyCommand.Parameters.Add("@st_hard", SqlDbType.Int).Value = user["st_hard"];
            MyCommand.Parameters.Add("@st_will1", SqlDbType.Int).Value = user["st_will1"];
            MyCommand.Parameters.Add("@st_will2", SqlDbType.NVarChar).Value = user["st_will2"];
            MyCommand.Parameters.Add("@st_need", SqlDbType.NVarChar).Value = user["st_need"];
            MyCommand.Parameters.Add("@st_goto", SqlDbType.Int).Value = user["st_goto"] == "" ? DBNull.Value : user["st_goto"];
            MyCommand.ExecuteNonQuery();
            str = "操作成功";
        }
        catch (Exception e)
        {
            Close();
            str = "操作失败";
        }
        Close();
        return str;
    }


    public string changeNeedstate(string id, string state)
    {
        string str = string.Empty;
        Open();
        try
        {
            SqlCommand MyCommand = new SqlCommand();
            MyCommand.Connection = MyConnection;
            SqlTransaction MyTrans = MyConnection.BeginTransaction("Tran");
            MyCommand.Transaction = MyTrans;
            string[] ids = id.Split(',');

            for (int i = 0; i < ids.Length - 1; i++)
            {
                MyCommand.Parameters.Clear();
                MyCommand.CommandText = "update recruit set re_needstate=@state where re_no=@re_no";
                MyCommand.Parameters.Add("@re_no", SqlDbType.Int).Value = ids[i];
                MyCommand.Parameters.Add("@state", SqlDbType.Int).Value = state;
                MyCommand.ExecuteNonQuery();
            }
            MyTrans.Commit();
            str = "操作成功";
        }
        catch (Exception e)
        {
            Close();
            str = "操作失败";
        }
        Close();
        return str;
    }


    public string deletecompanypay(string id)
    {
        string str = string.Empty;
        Open();
        try
        {
            SqlCommand MyCommand = new SqlCommand();
            MyCommand.Connection = MyConnection;
            SqlTransaction MyTrans = MyConnection.BeginTransaction("Tran");
            MyCommand.Transaction = MyTrans;
            string[] ids = id.Split(',');
            if (ids.Length == 1)
            {
                MyCommand.Parameters.Clear();
                MyCommand.CommandText = "delete from compayment where cm_no=@cmno";
                MyCommand.Parameters.Add("@cmno", SqlDbType.Int).Value = id;
                MyCommand.ExecuteNonQuery();
            }
            else
            {
                for (int i = 0; i < ids.Length - 1; i++)
                {
                    MyCommand.Parameters.Clear();
                    MyCommand.CommandText = "delete from compayment where cm_no=@cmno";
                    MyCommand.Parameters.Add("@cmno", SqlDbType.Int).Value = ids[i];
                    MyCommand.ExecuteNonQuery();
                }
            }
            MyTrans.Commit();
            str = "操作成功";
        }
        catch (Exception e)
        {
            Close();
            str = "操作失败";
        }
        Close();
        return str;
    }


    public Hashtable selectjobfair(string id)
    {
        Open();
        DataTable dt = new DataTable();
        try
        {
            SqlCommand MyCommand = MyConnection.CreateCommand();
            MyCommand.Connection = MyConnection;
            MyCommand.CommandText = "select * from jobfair where jf_no =@jf_no";
            MyCommand.Parameters.Add("@jf_no", SqlDbType.Int).Value = id;
            SqlDataAdapter sda = new SqlDataAdapter(MyCommand);

            sda.Fill(dt);
        }
        catch (Exception e)
        {
            Close();
        }
        Close();
        ArrayList al = DataTable2ArrayList(dt);
        return al.Count > 0 ? (Hashtable)al[0] : null;
    }


    public string updatejobfair(Hashtable user)
    {
        string str = string.Empty;
        Open();
        try
        {
            SqlCommand MyCommand = new SqlCommand();
            MyCommand.Connection = MyConnection;
            string id = (user["jf_no"] == null || user["jf_no"].ToString() == "" || user["jf_no"].ToString() == "0") ? "0" : user["jf_no"].ToString();
            if (id == "0")
            {
                MyCommand.CommandText = "insert into jobfair(jf_name,jf_memo,jf_inserttime,jf_insertip,if_insertuser,it_ishide)" +
                    " values(@jf_name,@jf_memo,getDate(),@jf_insertip,@if_insertuser,0)";
                MyCommand.Parameters.Add("@jf_insertip", SqlDbType.NVarChar).Value = user["jf_insertip"];
                MyCommand.Parameters.Add("@if_insertuser", SqlDbType.Int).Value = user["userid"];
            }
            else
            {
                MyCommand.CommandText = "update jobfair set jf_name=@jf_name,jf_memo=@jf_memo,if_modifytime=getDate(),if_modifyip=@if_modifyip,if_modifyuser=@if_modifyuser where jf_no=@jf_no";
                MyCommand.Parameters.Add("@jf_no", SqlDbType.Int).Value = id;
                MyCommand.Parameters.Add("@if_modifyip", SqlDbType.NVarChar).Value = user["jf_insertip"];
                MyCommand.Parameters.Add("@if_modifyuser", SqlDbType.Int).Value = user["userid"];
            }
            MyCommand.Parameters.Add("@jf_name", SqlDbType.NVarChar).Value = user["jf_name"];
            MyCommand.Parameters.Add("@jf_memo", SqlDbType.Text).Value = user["jf_memo"];
          
            MyCommand.ExecuteNonQuery();
            str = "操作成功";
        }
        catch (Exception e)
        {
            Close();
            str = "操作失败";
        }
        Close();
        return str;
    }


    public string deletejobfair(string id)
    {
        string str = string.Empty;
        Open();
        try
        {
            SqlCommand MyCommand = new SqlCommand();
            MyCommand.Connection = MyConnection;
            SqlTransaction MyTrans = MyConnection.BeginTransaction("Tran");
            MyCommand.Transaction = MyTrans;
            string[] ids = id.Split(',');
            if (ids.Length == 1)
            {
                MyCommand.Parameters.Clear();
                MyCommand.CommandText = "delete from jobfair where jf_no=@jf_no";
                MyCommand.Parameters.Add("@jf_no", SqlDbType.Int).Value = id;
                MyCommand.ExecuteNonQuery();
            }
            else
            {
                for (int i = 0; i < ids.Length - 1; i++)
                {
                    MyCommand.Parameters.Clear();
                    MyCommand.CommandText = "delete from jobfair where jf_no=@jf_no";
                    MyCommand.Parameters.Add("@jf_no", SqlDbType.Int).Value = ids[i];
                    MyCommand.ExecuteNonQuery();
                }
            }
            MyTrans.Commit();
            str = "操作成功";
        }
        catch (Exception e)
        {
            Close();
            str = "已有相关企业报名，不能删除";
        }
        Close();
        return str;
    }

    public string changeJobfairState(string str,string state) {
        Open();
        string res = "";
        try {
            SqlCommand MyCommand = new SqlCommand();
            MyCommand.Connection = MyConnection;
            SqlTransaction MyTrans = MyConnection.BeginTransaction("Tran");
            MyCommand.Transaction = MyTrans;
            string[] ids = str.Split(',');
           
            for (int i = 0; i < ids.Length - 1; i++)
            {
                MyCommand.Parameters.Clear();
                MyCommand.CommandText = "update jobfair set jf_ishide=@state where jf_no=@jf_no";
                MyCommand.Parameters.Add("@jf_no", SqlDbType.Int).Value = ids[i];
                MyCommand.Parameters.Add("@state", SqlDbType.Int).Value = state;
                MyCommand.ExecuteNonQuery();
            }
            MyTrans.Commit();
            res = "操作成功";
        }
        catch (Exception e) {
            Close();
            res = "操作失败";
        }
        Close();
        return res;
    }

//删除招聘会报名企业
    public string deletefairentry(string id)
    {
        string str = string.Empty;
        Open();
        try
        {
            SqlCommand MyCommand = new SqlCommand();
            MyCommand.Connection = MyConnection;
            SqlTransaction MyTrans = MyConnection.BeginTransaction("Tran");
            MyCommand.Transaction = MyTrans;
            string[] ids = id.Split(',');
            if (ids.Length == 1)
            {
                MyCommand.Parameters.Clear();
                MyCommand.CommandText = "delete from jobenter where je_feno=@je_feno";
                MyCommand.Parameters.Add("@je_feno", SqlDbType.Int).Value = id;
                MyCommand.ExecuteNonQuery();

                MyCommand.CommandText = "delete from fairentry where fe_no=@je_feno";
                MyCommand.ExecuteNonQuery();
            }
            else
            {
                for (int i = 0; i < ids.Length - 1; i++)
                {
                    MyCommand.Parameters.Clear();
                    MyCommand.CommandText = "delete from jobenter where je_feno=@je_feno";
                    MyCommand.Parameters.Add("@je_feno", SqlDbType.Int).Value = ids[i];
                    MyCommand.ExecuteNonQuery();

                    MyCommand.CommandText = "delete from fairentry where fe_no=@je_feno";
                    MyCommand.ExecuteNonQuery();
                }
            }
            MyTrans.Commit();
            str = "操作成功";
        }
        catch (Exception e)
        {
            Close();
            str = "操作失败";
        }
        Close();
        return str;
    }


    //审核招聘会报名企业
    public string changefairentry(string id,string state)
    {
        string str = string.Empty;
        Open();
        try
        {
            SqlCommand MyCommand = new SqlCommand();
            MyCommand.Connection = MyConnection;
            SqlTransaction MyTrans = MyConnection.BeginTransaction("Tran");
            MyCommand.Transaction = MyTrans;
            string[] ids = id.Split(',');
           
            for (int i = 0; i < ids.Length - 1; i++)
            {
                MyCommand.Parameters.Clear();
                MyCommand.CommandText = "update fairentry set fe_state=@state where fe_no=@fe_no";
                MyCommand.Parameters.Add("@fe_no", SqlDbType.Int).Value = ids[i];
                MyCommand.Parameters.Add("@state", SqlDbType.Int).Value = state;
                MyCommand.ExecuteNonQuery();
            }
            MyTrans.Commit();
            str = "操作成功";
        }
        catch (Exception e)
        {
            Close();
            str = "操作失败";
        }
        Close();
        return str;
    }


    public string returnjobfair(string id) {
        string res = string.Empty;
        Open();
        try {
            SqlCommand MyCommand = new SqlCommand();
            MyCommand.Connection = MyConnection;
            MyCommand.CommandText = "select jf_name from jobfair where jf_no=@jf_no";
            MyCommand.Parameters.Add("@jf_no", SqlDbType.Int).Value = id;
            res = MyCommand.ExecuteScalar().ToString();
        }
        catch (Exception e) {
            Close();
        }
        Close();
        return res;
    }


    public string returnCompany(string id) {
        string res = string.Empty;
        Open();
        try {
            SqlCommand MyCommand = new System.Data.SqlClient.SqlCommand();
            MyCommand.Connection = MyConnection;
            MyCommand.CommandText = "select cu_name+'['+case when fe_state=0 then '未审核' when fe_state=1 then '已通过' else '不通过' end+']' from companyuser left join fairentry on cu_no = fe_cuno  where  fe_no=@fe_no";
            MyCommand.Parameters.Add("@fe_no",SqlDbType.Int).Value = id;
            res = MyCommand.ExecuteScalar().ToString();
        }
        catch (Exception e) {
            Close();
        }
        Close();
        return res;
    }
}
